package com.qinggeng.project.tool.pay.controller;

import com.qinggeng.common.utils.poi.ExcelUtil;
import com.qinggeng.framework.aspectj.lang.annotation.Log;
import com.qinggeng.framework.aspectj.lang.enums.BusinessType;
import com.qinggeng.framework.web.controller.BaseController;
import com.qinggeng.framework.web.domain.AjaxResult;
import com.qinggeng.framework.web.page.TableDataInfo;
import com.qinggeng.project.tool.pay.domain.PayAlipay;
import com.qinggeng.project.tool.pay.service.IPayAlipayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 支付宝支付信息Controller
 *
 * @author qinggeng
 * @date 2020-02-13
 */
@RestController
@RequestMapping("/tool/alipay")
public class PayAlipayController extends BaseController
{
    @Autowired
    private IPayAlipayService payAlipayService;

    /**
     * 查询支付宝支付信息列表
     */
    @PreAuthorize("@ss.hasPermi('tool:alipay:list')")
    @GetMapping("/list")
    public TableDataInfo list(PayAlipay payAlipay)
    {
        startPage();
        List<PayAlipay> list = payAlipayService.selectPayAlipayList(payAlipay);
        return getDataTable(list);
    }

    /**
     * 导出支付宝支付信息列表
     */
    @PreAuthorize("@ss.hasPermi('tool:alipay:export')")
    @Log(title = "支付宝支付信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PayAlipay payAlipay)
    {
        List<PayAlipay> list = payAlipayService.selectPayAlipayList(payAlipay);
        ExcelUtil<PayAlipay> util = new ExcelUtil<PayAlipay>(PayAlipay.class);
        return util.exportExcel(list, "alipay");
    }

    /**
     * 获取支付宝支付信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('tool:alipay:query')")
    @GetMapping(value = "/{payId}")
    public AjaxResult getInfo(@PathVariable("payId") Long payId)
    {
        return AjaxResult.success(payAlipayService.selectPayAlipayById(payId));
    }

    /**
     * 新增支付宝支付信息
     */
    @PreAuthorize("@ss.hasPermi('tool:alipay:add')")
    @Log(title = "支付宝支付信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PayAlipay payAlipay)
    {
        return toAjax(payAlipayService.insertPayAlipay(payAlipay));
    }

    /**
     * 修改支付宝支付信息
     */
    @PreAuthorize("@ss.hasPermi('tool:alipay:edit')")
    @Log(title = "支付宝支付信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PayAlipay payAlipay)
    {
        return toAjax(payAlipayService.updatePayAlipay(payAlipay));
    }

    /**
     * 删除支付宝支付信息
     */
    @PreAuthorize("@ss.hasPermi('tool:alipay:remove')")
    @Log(title = "支付宝支付信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{payIds}")
    public AjaxResult remove(@PathVariable Long[] payIds)
    {
        return toAjax(payAlipayService.deletePayAlipayByIds(payIds));
    }
}
